package org.cbg.panel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JLayeredPane;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;

import org.cbg.bean.SearchGoodsBean;
import org.cbg.btn.TrslationBtn;
import org.cbg.frame.TrslationMainJframe;
import org.cbg.until.TraslationTableDahuabiUntil;
import org.come.Frame.ZhuFrame;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.CutButtonImage;
import org.come.until.GsonUtil;

import com.tool.tcpimg.UIUtils;

 

/**
 * 我要买大话币面板
 * 
 * @author Administrator
 * 
 */

public class TraslationWantBuyDahuabiJpanel extends JLayeredPane {

    /**
     * 下拉框：左，右 ；页码，上排序， 下排序
     */
    private JLabel chooseLeft, chooseRight, yema, upSort, downSort;
    // 实例化下拉列表框
    private TraslationSelectOptionJpanel chooseLeftModel, chooseRightModel;
    // 选项下拉监听标志(下拉0，没下拉1) 排序标识（0为默认排序， 1 为升序 ，2 为降序）
    private int leftFlag = 1, rightFlag = 1, showOrder = 0;

    /**
     * 页码按钮，首页，末页 , 左箭头, 右箭头
     */
    private TrslationBtn shouye, moye, leftArrows, rightArrows, chooseLeftArrows, chooseRightArrows;

    private JScrollPane jScrollPane;

    /**
     * 当前页码 最大页码
     *
     */
    private int dangqianyeshu = 1, zuidayema = 50;

    private TraslationWantBuyDahuabiModelJpanel buyDahuabiModelJpanel;

    public TraslationWantBuyDahuabiJpanel() {
        this.setPreferredSize(new Dimension(760, 460));
        this.setOpaque(false);
        this.setLayout(null);


        buyDahuabiModelJpanel = new TraslationWantBuyDahuabiModelJpanel();
        buyDahuabiModelJpanel.setBounds(8, 58, 760, 100);
        buyDahuabiModelJpanel.setOpaque(false);
        // this.add(buyDahuabiModelJpanel);

        jScrollPane = new JScrollPane();
        jScrollPane.setBounds(8, 63, 750, 372);
        TraslationTableDahuabiUntil.TableModel(jScrollPane, 10);
        jScrollPane.getVerticalScrollBar().setUnitIncrement(50);

        chooseLeft = new JLabel("一千万");
        chooseRight = new JLabel("一百亿");
        chooseLeftArrows = new TrslationBtn("inkImg/number/b4/xlaj.png", 1);
        chooseRightArrows = new TrslationBtn("inkImg/number/b4/xlaj.png", 1);

        chooseLeft.setForeground(UIUtils.COLOR_cbg2);
        chooseRight.setForeground(UIUtils.COLOR_cbg2);

        chooseLeft.setBounds(55, 8, 90, 20);
        chooseRight.setBounds(170, 8, 90, 20);
        chooseLeftArrows.setBounds(130, 13, 13, 13);
        chooseRightArrows.setBounds(247, 13, 13, 13);
        String[] rowDataLeft = { "一千万","一亿", "二亿", "三亿", "四亿", "十亿", "二十亿", "三十亿", "四十亿", "十亿", "五十亿", "六十亿", "七十亿", "八十亿",
                "九十亿", "一百亿" };
        String[] rowDataRight = { "一亿", "二亿", "三亿", "四亿", "十亿", "二十亿", "三十亿", "四十亿", "十亿", "五十亿", "六十亿", "七十亿", "八十亿",
                "九十亿", "一百亿" };
        // 左边面板
        chooseLeftModel = new TraslationSelectOptionJpanel(100, 193, "inkImg/old/1/Z1000.png", rowDataLeft);
        chooseLeftModel.setBounds(48, 30, 100, 193);
        chooseLeftModel.setVisible(false);
        // 右边面板
        chooseRightModel = new TraslationSelectOptionJpanel(100, 193, "inkImg/old/1/Z1000.png", rowDataRight);
        chooseRightModel.setBounds(165, 30, 100, 193);
        chooseRightModel.setVisible(false);
        // 左边下拉监听
        chooseLeftArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (leftFlag == 1) {
                    chooseLeftModel.setVisible(true);
                    leftFlag = 0;
                } else {
                    chooseLeftModel.setVisible(false);
                    leftFlag = 1;
                }

            }
        });
        // 右边下拉监听
        chooseRightArrows.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (rightFlag == 1) {
                    chooseRightModel.setVisible(true);
                    rightFlag = 0;
                } else {
                    chooseRightModel.setVisible(false);
                    rightFlag = 1;
                }
            }
        });
        // 左侧列表进行监听
        chooseLeftModel.getJlist().addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {

                String getname = chooseLeftModel.getJlist().getSelectedValue();
                chooseLeft.setText(getname);
                chooseLeftModel.setVisible(false);
                leftFlag = 1;
                dangqianyeshu = 1;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                 * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(2);
                searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                        + changeMath(chooseRight.getText()));
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
            }
        });

        // 右侧监听
        chooseRightModel.getJlist().addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                String getname = chooseRightModel.getJlist().getSelectedValue();
                chooseRight.setText(getname);
                chooseRightModel.setVisible(false);
                rightFlag = 1;
                dangqianyeshu = 1;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                 * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(2);
                searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                        + changeMath(chooseRight.getText()));
                searchGoodsBean.setPageNum(dangqianyeshu);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
            }
        });

        this.add(chooseLeftArrows);
        this.add(chooseRightArrows);
        this.add(chooseLeftModel, 10, 2);
        this.add(chooseLeft);
        this.add(chooseRight);
        this.add(chooseRightModel, 10, 4);

        /**
         * 页码设置
         */
        yema = new JLabel(dangqianyeshu + "/" + zuidayema);
        yema.setBounds(258+91, 442, 58, 17);
        yema.setForeground(UIUtils.COLOR_cbg8);
        yema.setOpaque(false);
        yema.setHorizontalAlignment(SwingConstants.CENTER);
        this.add(yema);

        shouye = new TrslationBtn("inkImg/number/b4/fy1.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        shouye.setBounds(287, 442, 40, 20);
        this.add(shouye);
        shouye.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != 1) {
                    dangqianyeshu = 1;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                     * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(2);
                    searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                            + changeMath(chooseRight.getText()));
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在首页");
                }
            }

        });

        leftArrows = new TrslationBtn("inkImg/number/b4/fy2.png", 1);
        leftArrows.setBounds(326, 442, 19, 20);
        this.add(leftArrows);
        leftArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu > 1) {
                    dangqianyeshu--;
                    yema.setText(dangqianyeshu + "/" + zuidayema);

                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                     * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(2);
                    searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                            + changeMath(chooseRight.getText()));
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有上一页了");
                }
            }
        });

        moye = new TrslationBtn("inkImg/number/b4/fy4.png", 1, UIUtils.COLOR_BTNTEXT, UIUtils.TEXT_FONT, "");
        moye.setBounds(433, 442, 40, 20);
        this.add(moye);

        moye.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu != zuidayema) {
                    dangqianyeshu = zuidayema;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                     * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(2);
                    searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                            + changeMath(chooseRight.getText()));
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);

                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已在末页");
                }
            }
        });

        rightArrows = new TrslationBtn("inkImg/number/b4/fy3.png", 1);
        rightArrows.setBounds(411, 442, 19, 20);
        this.add(rightArrows);
        rightArrows.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                if (dangqianyeshu < zuidayema) {
                    dangqianyeshu++;
                    yema.setText(dangqianyeshu + "/" + zuidayema);
                    /**
                     * 将搜索信息传给服务器 1、初始化协议
                     * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                     * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                     */
                    SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                    searchGoodsBean.setSaletype(2);
                    searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                            + changeMath(chooseRight.getText()));
                    searchGoodsBean.setPageNum(dangqianyeshu);
                    searchGoodsBean.setOrder(showOrder);
                    String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                            GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                    SendMessageUntil.toServer(sendmes);
                    TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
                } else {
                    ZhuFrame.getZhuJpanel().addPrompt2("已经没有下一页了");
                }
            }
        });

        /**
         * 排序
         */
        upSort = new JLabel();
        upSort.setBounds(280, 38, 10, 18);
        upSort.setBorder(null);
        upSort.setBackground(null);
        upSort.setOpaque(false);
        upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
        this.add(upSort);
        upSort.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1003.png", 10, 18));
                downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1004.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 1;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                 * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(2);
                searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                        + changeMath(chooseRight.getText()));
                searchGoodsBean.setPageNum(1);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
            }
        });

        downSort = new JLabel();
        downSort.setBounds(296, 39, 10, 18);
        downSort.setBorder(null);
        downSort.setBackground(null);
        downSort.setOpaque(false);
        downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1004.png", 10, 18));
        this.add(downSort);
        downSort.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                // TODO Auto-generated method stub
                upSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1002.png", 10, 18));
                downSort.setIcon(CutButtonImage.getImage("inkImg/old/1/Z1005.png", 10, 18));
                dangqianyeshu = 1;
                showOrder = 2;

                /**
                 * 将搜索信息传给服务器 1、初始化协议
                 * 2、修改搜索类型(1为首页搜索,2为大话币搜索,3道具,4召唤兽,5装备,6灵宝,7公示期,8收藏) 3、条件搜索
                 * 4、确认页码 5、搜索条件的整合 转换为json字符串 6、上传给服务器
                 */
                SearchGoodsBean searchGoodsBean = new SearchGoodsBean();
                searchGoodsBean.setSaletype(2);
                searchGoodsBean.setContiontype(changeMath(chooseLeft.getText()) + "-"
                        + changeMath(chooseRight.getText()));
                searchGoodsBean.setPageNum(1);
                searchGoodsBean.setOrder(showOrder);
                String sendmes = Agreement.getAgreement().searchGoodsAgreement(
                        GsonUtil.getGsonUtil().getgson().toJson(searchGoodsBean));
                SendMessageUntil.toServer(sendmes);
                TrslationMainJframe.getTrslationMainJframe().setPanelOpen(2);
            }
        });

        this.add(jScrollPane, 10, -1);

    }

    private ImageIcon icon1;

    @Override
    protected void paintComponent(Graphics g) {
        // TODO Auto-generated method stub
        super.paintComponent(g);
        if (icon1 == null) {
            icon1 = new ImageIcon("inkImg/number/b4/dhbxq.png");
        }
        g.drawImage(icon1.getImage(), 0, 5, 760, 55, this);



    }

    /**
     * 刷新页面的页码
     *
     * @param dangqianyema
     * @param zuidayema
     *
     */
    public void setPage(int zuidayema) {
        this.zuidayema = zuidayema;
        yema.setText(this.dangqianyeshu + "/" + this.zuidayema);
    }

    /**
     * 将汉字转换为对应的数字 { "一亿" },{ "十亿" }, { "二亿" }, { "三亿" }, { "四亿" }, { "五亿" }, {
     * "六亿" }, { "七亿" }, { "八亿" }, { "九亿" }, { "一百亿" }
     *
     * @param mathChina
     * @return
     */

    public static BigDecimal changeMath(String mathChina) {
        BigDecimal math = null;

        switch (mathChina) {
            case "一千万":
                math = new BigDecimal("10000000");
                break;
            case "一亿":
                math = new BigDecimal("100000000");
                break;
            case "十亿":
                math = new BigDecimal("1000000000");
                break;
            case "二十亿":
                math = new BigDecimal("2000000000");
                break;
            case "三十亿":
                math = new BigDecimal("3000000000");
                break;
            case "四十亿":
                math = new BigDecimal("4000000000");
                break;
            case "五十亿":
                math = new BigDecimal("5000000000");
                break;
            case "六十亿":
                math = new BigDecimal("6000000000");
                break;
            case "七十亿":
                math = new BigDecimal("7000000000");
                break;
            case "八十亿":
                math = new BigDecimal("8000000000");
                break;
            case "九十亿":
                math = new BigDecimal("9000000000");
                break;
            case "一百亿":
                math = new BigDecimal("10000000000");
                break;
        }
        return math;
    }


    public JLabel getChooseLeft() {
        return chooseLeft;
    }

    public void setChooseLeft(JLabel chooseLeft) {
        this.chooseLeft = chooseLeft;
    }

    public JLabel getChooseRight() {
        return chooseRight;
    }

    public void setChooseRight(JLabel chooseRight) {
        this.chooseRight = chooseRight;
    }

    public JLabel getYema() {
        return yema;
    }

    public void setYema(JLabel yema) {
        this.yema = yema;
    }

    public JLabel getUpSort() {
        return upSort;
    }

    public void setUpSort(JLabel upSort) {
        this.upSort = upSort;
    }

    public JLabel getDownSort() {
        return downSort;
    }

    public void setDownSort(JLabel downSort) {
        this.downSort = downSort;
    }

    public TraslationSelectOptionJpanel getChooseLeftModel() {
        return chooseLeftModel;
    }

    public void setChooseLeftModel(TraslationSelectOptionJpanel chooseLeftModel) {
        this.chooseLeftModel = chooseLeftModel;
    }

    public TraslationSelectOptionJpanel getChooseRightModel() {
        return chooseRightModel;
    }

    public void setChooseRightModel(TraslationSelectOptionJpanel chooseRightModel) {
        this.chooseRightModel = chooseRightModel;
    }

    public int getLeftFlag() {
        return leftFlag;
    }

    public void setLeftFlag(int leftFlag) {
        this.leftFlag = leftFlag;
    }

    public int getRightFlag() {
        return rightFlag;
    }

    public void setRightFlag(int rightFlag) {
        this.rightFlag = rightFlag;
    }

    public int getShowOrder() {
        return showOrder;
    }

    public void setShowOrder(int showOrder) {
        this.showOrder = showOrder;
    }

    public TrslationBtn getShouye() {
        return shouye;
    }

    public void setShouye(TrslationBtn shouye) {
        this.shouye = shouye;
    }

    public TrslationBtn getMoye() {
        return moye;
    }

    public void setMoye(TrslationBtn moye) {
        this.moye = moye;
    }

    public TrslationBtn getLeftArrows() {
        return leftArrows;
    }

    public void setLeftArrows(TrslationBtn leftArrows) {
        this.leftArrows = leftArrows;
    }

    public TrslationBtn getRightArrows() {
        return rightArrows;
    }

    public void setRightArrows(TrslationBtn rightArrows) {
        this.rightArrows = rightArrows;
    }

    public TrslationBtn getChooseLeftArrows() {
        return chooseLeftArrows;
    }

    public void setChooseLeftArrows(TrslationBtn chooseLeftArrows) {
        this.chooseLeftArrows = chooseLeftArrows;
    }

    public TrslationBtn getChooseRightArrows() {
        return chooseRightArrows;
    }

    public void setChooseRightArrows(TrslationBtn chooseRightArrows) {
        this.chooseRightArrows = chooseRightArrows;
    }

    public JScrollPane getjScrollPane() {
        return jScrollPane;
    }

    public void setjScrollPane(JScrollPane jScrollPane) {
        this.jScrollPane = jScrollPane;
    }

    public int getDangqianyeshu() {
        return dangqianyeshu;
    }

    public void setDangqianyeshu(int dangqianyeshu) {
        this.dangqianyeshu = dangqianyeshu;
    }

    public int getZuidayema() {
        return zuidayema;
    }

    public void setZuidayema(int zuidayema) {
        this.zuidayema = zuidayema;
    }

    public TraslationWantBuyDahuabiModelJpanel getBuyDahuabiModelJpanel() {
        return buyDahuabiModelJpanel;
    }

    public void setBuyDahuabiModelJpanel(TraslationWantBuyDahuabiModelJpanel buyDahuabiModelJpanel) {
        this.buyDahuabiModelJpanel = buyDahuabiModelJpanel;
    }

    public ImageIcon getIcon1() {
        return icon1;
    }

    public void setIcon1(ImageIcon icon1) {
        this.icon1 = icon1;
    }

}
